package com.zh.remote.fallback;

import com.zh.remote.api.LoginApi;
import com.zh.remote.pojo.param.CreateLoginDto;
import com.zh.remote.pojo.param.UpdateLoginDto;
import com.zh.result.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LoginApiFallback implements FallbackFactory<LoginApi> {
    @Override
    public LoginApi create(Throwable cause) {
        return new LoginApi(){
            @Override
            public JSONResult createLogin(CreateLoginDto createLogin) {
                cause.printStackTrace();
                // 打印异常日志
                log.error("服务调用失败{}", cause.getMessage());
                return JSONResult.error("远程调用失败" + cause.getMessage());
            }

            @Override
            public JSONResult updateLogin(UpdateLoginDto updateLogin) {
                //打印异常日志
                cause.printStackTrace();
                log.error("服务调用失败{}", cause.getMessage());
                return JSONResult.error("远程调用失败" + cause.getMessage());
            }
        };
    }
}
